package gupao.springboot.redis.controller;

import gupao.springboot.redis.dto.Product;
import gupao.springboot.redis.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
public class ProductController {


    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public List<Product> selectProduct() {
        return productService.selectProduct();
    }

    @RequestMapping(value = "/id",method = RequestMethod.GET)
    @ResponseBody
    public Long getId() {
        return productService.getId();
    }


    @RequestMapping(value = "/pay",method = RequestMethod.GET)
    @ResponseBody
    public String pay(@RequestParam("id") Long id) throws InterruptedException {
        return productService.pay(id);
    }

    @RequestMapping(value = "/pay_lock",method = RequestMethod.GET)
    @ResponseBody
    public String payRedisson(@RequestParam("id") Long id) throws InterruptedException {
        return productService.payRedisson(id);
    }

    @RequestMapping(value = "/pay_multi",method = RequestMethod.GET)
    @ResponseBody
    public String payMultiLock(@RequestParam("id") Long id) throws InterruptedException {
        return productService.payMultiLock(id);
    }

//    @RequestMapping(value = "/statistic",method = RequestMethod.GET)
//    @ResponseBody
//    public ProductStatics statistic(@RequestParam("id") Integer id)  {
//        return productService.getStatics(id);
//    }

    @RequestMapping(value = "/pv",method = RequestMethod.GET)
    @ResponseBody
    public Integer addPv(@RequestParam("id") Integer id)  {
        return productService.addPv(id);
    }

    @RequestMapping(value = "/uv",method = RequestMethod.GET)
    @ResponseBody
    public Integer addUv(@RequestParam("id") Integer id)  {
        return productService.adduv(id);
    }

    @RequestMapping(value = "/rank_init",method = RequestMethod.GET)
    @ResponseBody
    public void rankInit()  {
        productService.rankInit();
    }


    @RequestMapping(value = "/rank",method = RequestMethod.GET)
    @ResponseBody
    public Set rank()  {
       return  productService.rank();
    }

    @RequestMapping(value = "/test",method = RequestMethod.GET)
    @ResponseBody
    public long test()  {
        return productService.test();
    }

    @RequestMapping(value = "/test1",method = RequestMethod.GET)
    @ResponseBody
    public long test1()  {
        return productService.test1();
    }

}
